<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/header.jsp"%>
<div class="clearfix"></div>
<div class="row">
	<div class="col-md-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>APP信息管理维护 <i class="fa fa-user"></i></h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<form id="fm" method="post" action="${ctx}/app/list">
			    <ul>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">软件名称</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<input name="appName" type="text" class="form-control col-md-7 col-xs-12" id="appName">
							</div>
						</div>
					</li>			
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">APP状态</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<select name="status" class="form-control" id="status">
									<option value=""></option>
									<option value="1">待审核</option>
									<option value="2">审核通过</option>
									<option value="3">已上架</option>
									<option value="4">已下架</option>
									<option value="5">审核未通过</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">所属平台</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<select name="appType" class="form-control" id="appType">
									<option value=""></option>
									<option value="1">android</option>
									<option value="2">ios</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">一级分类</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
								<select id="categoryLevel1" name="categoryLevel1" class="form-control" id="categoryLevel1" onchange="getLevel2()">
									<option value="">-请选择一级分类-</option>
									<!--TODO 一级分类-->
									<option value="1">游戏</option>
									<option value="2">应用</option>
        						</select>
							</div>
						</div>
					</li>
					<li>
						<div class="form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12">二级分类</label>
							<div class="col-md-6 col-sm-6 col-xs-12">
        						<select name="categoryLevel2" id="categoryLevel2" class="form-control" id="categoryLevel2" >
        							<option value="">请选择二级分类</option>
        							<!--TODO 二级分类-->
        						</select>
							</div>
						</div>
					</li>
					<li><button type="submit" class="btn btn-primary"> 查 &nbsp;&nbsp;&nbsp;&nbsp;询 </button></li>
				</ul>
			</form>
		</div>
	</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
	<div class="x_panel">
		<div class="x_content">
			<p class="text-muted font-13 m-b-30"></p>
			<div id="datatable-responsive_wrapper"
				class="dataTables_wrapper form-inline dt-bootstrap no-footer">
				<div class="row">
					<div class="col-sm-12">
					<a href="${ctx}/app/add" class="btn btn-success btn-sm">新增APP</a>
						<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed"
							cellspacing="0" width="100%" role="grid" aria-describedby="datatable-responsive_info" style="width: 100%;">
							<thead>
								<tr role="row">
									<th>软件名称</th>
									<th>软件大小(单位:M)</th>
									<th>所属分类(一级分类、二级分类)</th>
									<th>状态</th>
									<th>版本名称</th>
									<th>版本号</th>
									<th>所属平台</th>
									<th>下载次数</th>
									<th>创建时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="appInfo" items="${pageInfo.list }" varStatus="status">
									<tr role="row" class="odd">
										<td>${appInfo.appName }</td>
										<td>${appInfo.size }</td>
										<td>${appInfo.appCategory1.categoryName} -> ${appInfo.appCategory2.categoryName}</td>
										<td>
											<c:choose>
												<c:when test="${appInfo.status==1 }">待审核</c:when>
												<c:when test="${appInfo.status==2 }">审核通过</c:when>
												<c:when test="${appInfo.status==3 }">已上架</c:when>
												<c:when test="${appInfo.status==4 }">已下架</c:when>
												<c:otherwise>审核未通过</c:otherwise>
											</c:choose>
										</td>
										<td>${appInfo.versionName }</td>
										<td>${appInfo.versionCode }</td>
										
										<c:if test="${appInfo.appType==1 }">
											<td>android</td>
										</c:if>
										<c:if test="${appInfo.appType==2 }">
											<td>ios</td>
										</c:if>
										<td>${appInfo.download }</td>
										<td>
											<fmt:formatDate value="${appInfo.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/>
										</td>
										<td>
											<div class="btn-group">
						                      <button type="button" class="btn btn-danger">点击操作</button>
						                      <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
						                        <span class="caret"></span>
						                        <span class="sr-only">Toggle Dropdown</span>
						                      </button>
												<%--1 未审核--%>
												<%--2 审核通过--%>
												<%--3 已上架--%>
												<%--4 已下架--%>
												<%--5 审核未通过--%>
													<ul class="dropdown-menu" role="menu">
														<li><c:choose>
																<c:when
																	test="${appInfo.status == 2 || appInfo.status == 4}">
																	<a class="saleSwichOpen" saleSwitch="open"
																		data-toggle="tooltip" data-placement="left" title=""
																		data-original-title="恭喜您，您的审核已经通过，您可以点击上架发布您的APP">上架</a>
																</c:when>
																<c:when test="${appInfo.status == 3}">
																	<a class="saleSwichClose" saleSwitch="close"
																		data-toggle="tooltip" data-placement="left" title=""
																		data-original-title="您可以点击下架来停止发布您的APP，市场将不提供APP的下载">下架</a>
																</c:when>
															</c:choose></li>
														<li><a class="addVersion"
															data-toggle="tooltip" data-placement="left" title=""
															data-original-title="新增APP版本信息"
															appId="${appInfo.appId }">新增版本</a></li>
														<li><a class="modifyAppInfo"
															data-toggle="tooltip"
															data-placement="left" title=""
															data-original-title="修改APP基础信息"
															appId="${appInfo.appId }"
															status="${appInfo.status }">修改</a></li>
														<li><a class="viewApp" 
															data-toggle="tooltip" data-placement="left" title=""
															data-original-title="查看APP基础信息以及全部版本信息" 
															appId="${appInfo.appId }">查看</a></li>
														<li><a class="deleteApp" 
															data-toggle="tooltip" data-placement="left" title=""
															data-original-title="删除APP基础信息以及全部版本信息"
															appId="${appInfo.appId }">删除</a></li>
													</ul>
												</div>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
				<div class="row">
					<!--TODO 分页-->
					<a href="#" onclick="getAppList(1)">首页</a>
                    <c:if test="${pageInfo.pageNum>1}">
                        <a href="#" onclick="getAppList(${pageInfo.pageNum-1})">上一页</a>
                    </c:if>
                    <c:if test="${pageInfo.pageNum<pageInfo.pages}">
                        <a href="#" onclick="getAppList(${pageInfo.pageNum+1})">下一页</a>
                    </c:if>
					<a href="#" onclick="getAppList(${pageInfo.pages})">末页</a>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
<%@include file="../common/footer.jsp"%>
<script src="${ctx}/statics/localjs/appinfolist.js"></script>

<script>
    function getLevel2() {
        var c1=$("#categoryLevel1");
        var c2=$("#categoryLevel2");
        $.get(
            "${ctx}/app/getLevel2",
            {parentId:c1.val()},//携带的参数
            function(data){
                c2.html("<option></option>");
                //使用each函数遍历返回的list数据
                // index：元素下标，element:元素
                $(data).each(function (index,element) {
                    //将元素内容取出，拼接层option标签，添加到二级分类<select>中
                    c2.append("<option value='"+element.id+"'>"+element.categoryName+"</option>");
                });
                $("#categoryLevel2").val(${requestScope.appInfo.categoryLevel2});//选中之前查询的二级分类
            },
            "json");//json是返回的数据类型

    }

	$(function () {
	    $("#appName").val("${requestScope.appInfo.appName}");//填入之前搜索的appName
        $("#status").val(${requestScope.appInfo.status});//选中之前搜索的状态
        $("#appType").val(${requestScope.appInfo.appType});//选中之前搜索的平台类型
        $("#categoryLevel1").val(${requestScope.appInfo.categoryLevel1});//选中之前搜索的一级分类
        //重新获取二级分类
        if($("#categoryLevel1").val()!=""){
            getLevel2();
        }
    });

    function getAppList(page) {//需要传递当前页数
        //先通过attr()修改action的地址值
        $("#fm").attr("action","${ctx}/app/list?userId=${user.userId}&page="+page).submit();//获取表单信息，进行分页查询
    }

</script>
